package org.standard.base.action;

import java.io.File;
import java.util.List;

import org.standard.base.model.BaseRole;
import org.standard.base.model.BaseUser;
import org.standard.commons.struts2.BaseAction;
import org.standard.commons.utils.Constants;
import org.standard.commons.utils.FlipPageInfo;
import org.standard.commons.utils.Utils;
import org.standard.message.model.Message;
import org.standard.notice.model.Notice;
import org.standard.sys.model.SysFace;
import org.standard.sys.model.SysMenu;
import org.standard.sys.service.SysFaceService;
import org.standard.sys.service.SysMenuService;
import org.standard.base.service.BaseRoleService;

public class IndexAction extends BaseAction {
	private SysMenuService sysMenuService;
	private SysFaceService sysFaceService;
	private BaseRoleService baseRoleService;
	private List<SysMenu> sysMenus;
	private List boutGrounds;
	private SysFace face; 
	private String ieTitle;
	private String statusText;
	private String bannerText;
	private String bannerFont;
	private String logoName;
	private String logoWidth;
	private String logoHight;
	private String bmpTopName;
	private String bmpTopWidth;
	private String bmpTopHight;
	private String bmpDeskName;
	private String bmpLoginName;
	private BaseUser user;
	private BaseRole role;
	private FlipPageInfo flipPageInfo_Notice = new FlipPageInfo();
	{
		flipPageInfo_Notice.setSize(10);
	}
	private FlipPageInfo flipPageInfo_Message = new FlipPageInfo();
	{
		flipPageInfo_Message.setSize(10);
	}
	int desktopSize = 3;
	private FlipPageInfo flipPageInfo_1 = new FlipPageInfo();
	{
		flipPageInfo_1.setSize(10);
	}
	private FlipPageInfo flipPageInfo_2 = new FlipPageInfo();
	{
		flipPageInfo_2.setSize(desktopSize);
	}
	private FlipPageInfo flipPageInfo_3 = new FlipPageInfo();
	{
		flipPageInfo_3.setSize(desktopSize);
	}
	private FlipPageInfo flipPageInfo_4 = new FlipPageInfo();
	{
		flipPageInfo_4.setSize(desktopSize);
	}
	private FlipPageInfo flipPageInfo_5 = new FlipPageInfo();
	{
		flipPageInfo_5.setSize(desktopSize);
	}
	
	
	
	
	public String viewTop(){
		//获得登录用户的身份
		user = (BaseUser)request.getSession().getAttribute(Constants.SESSION_USER);
		if(null!=user.getRoleId()&&!"".equals(user.getRoleId()))
			role=baseRoleService.findByRoleId(user.getRoleId());
		else{
			role=new BaseRole();
			role.setRoleName("");
			}
		face=sysFaceService.search();
		//是否有界面设置的参数
		if(face!=null)
		{
		//判定是否顶部图片
		if(face.getBmpTopName()!=null&&!"".equals(face.getBmpTopName()))
		{
			bmpTopName=face.getBmpTopName();	
		}
			//判定是否有LOGO
		if(face.getLogoName()!=null&&!"".equals(face.getLogoName()))
			logoName= Constants.FACE_PHOTO_DIR+face.getLogoName();	
		}
		return "viewTop";
	}
	
	public String viewNav(){
		//获得登录用户的身份
		user = (BaseUser)request.getSession().getAttribute(Constants.SESSION_USER);
		if(null!=user.getRoleId()&&!"".equals(user.getRoleId()))
			role=baseRoleService.findByRoleId(user.getRoleId());
		else{
			role=new BaseRole();
			role.setRoleName("");
			}
		face=sysFaceService.search();
		//是否有界面设置的参数
		if(face!=null)
		{
		//判定是否顶部图片
		if(face.getBmpTopName()!=null&&!"".equals(face.getBmpTopName()))
		{
			bmpTopName=face.getBmpTopName();	
		}
			//判定是否有LOGO
		if(face.getLogoName()!=null&&!"".equals(face.getLogoName()))
			logoName= Constants.FACE_PHOTO_DIR+face.getLogoName();	
		}
		return "viewNav";
	}
	
	public String viewLeft(){
		BaseUser user = (BaseUser)request.getSession().getAttribute("user");
		
		sysMenus = sysMenuService.indexLeft(user);
		
		return "viewLeft";
		}
	
	public String viewMain(){
		face=sysFaceService.search();
		//是否有界面设置的参数
		if(face!=null)
		{
		//判定是否桌面图片
		if(face.getBmpDeskName()!=null&&!"".equals(face.getBmpDeskName()))
			bmpDeskName= Constants.FACE_PHOTO_DIR+face.getBmpDeskName();	
		}
		user = (BaseUser) session.get(Constants.SESSION_USER);
		//提案系统
		if ("0".equals(user.getS())) {
			searchNotice();
			receive();
			return "viewMain";
		} else {
			suggest();
			return "viewMain_suggest";
		}
		
	}
	public void searchNotice() {
		
		String [][]sort = {
				{"Notice.1date", "1"},
		};
		flipPageInfo_Notice = service.findPOJOList(Notice.class, flipPageInfo_Notice , null, sort);
	}
	public void receive() {
		BaseUser user = (BaseUser) session.get(Constants.SESSION_USER);
		String [][]search = {
				{"receiveUserId", user.getUserId()}
		};
		String [][]sort = {
				{"date", "1"},
		};
		flipPageInfo_Message = service.findPOJOList(Message.class, flipPageInfo_Message , search, sort);
	}
	public void suggest() {
		flipPageInfo_1 = service.findPOJOList("from Notice where type = 1 order by date desc", flipPageInfo_1);
		flipPageInfo_2 = service.findPOJOList("from Notice where type = 2 order by date desc", flipPageInfo_2);
		flipPageInfo_3 = service.findPOJOList("from Notice where type = 3 order by date desc", flipPageInfo_3);
		flipPageInfo_4 = service.findPOJOList("from Notice where type = 4 order by date desc", flipPageInfo_4);
		flipPageInfo_5 = service.findPOJOList("from Notice where type = 5 order by date desc", flipPageInfo_5);
	}
	
	public String loginindex(){
		/**
		 * 设置登陆界面图片
		 */
		//获得登陆界面设置的参数
		face=sysFaceService.search();
		
		//是否有登陆界面设置的参数
		if(face!=null)
		{
		//判定是否登陆界面图片
		if(face.getBmpLoginName()!=null&&!"".equals(face.getBmpLoginName()))
			bmpLoginName= Constants.FACE_PHOTO_DIR+face.getBmpLoginName();	
		}

		if (user != null && 
				("0".equals(user.getS()) || "1".equals(user.getS()))) {
			return "index";
		} else {
			return "";
		}
		
	}
	
	
	public String frontIndex(){
		
		face=sysFaceService.search();
		
		return "frontIndex";
	}
	//加载场地图片
	public String toGround(){
		return "to_ground";
	}
	
	public String exit(){
		user = (BaseUser) request.getSession().getAttribute(Constants.SESSION_USER);
		request.getSession().removeAttribute(Constants.SESSION_DEPT);
		request.getSession().removeAttribute(Constants.SESSION_ROLE);
		request.getSession().removeAttribute(Constants.SESSION_USER);
		return "exit";
	}
	
	public String viewFoot(){
		face=sysFaceService.search();
		return "viewFoot";
	}

	public List<SysMenu> getSysMenus() {
		return sysMenus;
	}

	public void setSysMenus(List<SysMenu> sysMenus) {
		this.sysMenus = sysMenus;
	}

	public void setSysMenuService(SysMenuService sysMenuService) {
		this.sysMenuService = sysMenuService;
	}

	public SysFaceService getSysFaceService() {
		return sysFaceService;
	}

	public void setSysFaceService(SysFaceService sysFaceService) {
		this.sysFaceService = sysFaceService;
	}

	public SysFace getFace() {
		return face;
	}

	public void setFace(SysFace face) {
		this.face = face;
	}

	public String getIeTitle() {
		return ieTitle;
	}

	public void setIeTitle(String ieTitle) {
		this.ieTitle = ieTitle;
	}

	public String getStatusText() {
		return statusText;
	}

	public void setStatusText(String statusText) {
		this.statusText = statusText;
	}

	public String getBannerText() {
		return bannerText;
	}

	public void setBannerText(String bannerText) {
		this.bannerText = bannerText;
	}

	public String getBannerFont() {
		return bannerFont;
	}

	public void setBannerFont(String bannerFont) {
		this.bannerFont = bannerFont;
	}

	public String getLogoName() {
		return logoName;
	}

	public void setLogoName(String logoName) {
		this.logoName = logoName;
	}

	public String getLogoWidth() {
		return logoWidth;
	}

	public void setLogoWidth(String logoWidth) {
		this.logoWidth = logoWidth;
	}

	public String getLogoHight() {
		return logoHight;
	}

	public void setLogoHight(String logoHight) {
		this.logoHight = logoHight;
	}

	public String getBmpTopName() {
		return bmpTopName;
	}

	public void setBmpTopName(String bmpTopName) {
		this.bmpTopName = bmpTopName;
	}

	public String getBmpTopWidth() {
		return bmpTopWidth;
	}

	public void setBmpTopWidth(String bmpTopWidth) {
		this.bmpTopWidth = bmpTopWidth;
	}

	public String getBmpTopHight() {
		return bmpTopHight;
	}

	public void setBmpTopHight(String bmpTopHight) {
		this.bmpTopHight = bmpTopHight;
	}

	public String getBmpDeskName() {
		return bmpDeskName;
	}

	public void setBmpDeskName(String bmpDeskName) {
		this.bmpDeskName = bmpDeskName;
	}

	public String getBmpLoginName() {
		return bmpLoginName;
	}

	public void setBmpLoginName(String bmpLoginName) {
		this.bmpLoginName = bmpLoginName;
	}

	public SysMenuService getSysMenuService() {
		return sysMenuService;
	}

	public BaseUser getUser() {
		return user;
	}

	public void setUser(BaseUser user) {
		this.user = user;
	}

	public BaseRole getRole() {
		return role;
	}

	public void setRole(BaseRole role) {
		this.role = role;
	}

	public BaseRoleService getBaseRoleService() {
		return baseRoleService;
	}

	public void setBaseRoleService(BaseRoleService baseRoleService) {
		this.baseRoleService = baseRoleService;
	}

	public List getBoutGrounds() {
		return boutGrounds;
	}

	public void setBoutGrounds(List boutGrounds) {
		this.boutGrounds = boutGrounds;
	}

	public FlipPageInfo getFlipPageInfo_Notice() {
		return flipPageInfo_Notice;
	}

	public void setFlipPageInfo_Notice(FlipPageInfo flipPageInfo_Notice) {
		this.flipPageInfo_Notice = flipPageInfo_Notice;
	}

	public FlipPageInfo getFlipPageInfo_Message() {
		return flipPageInfo_Message;
	}

	public void setFlipPageInfo_Message(FlipPageInfo flipPageInfo_Message) {
		this.flipPageInfo_Message = flipPageInfo_Message;
	}

	public FlipPageInfo getFlipPageInfo_1() {
		return flipPageInfo_1;
	}

	public void setFlipPageInfo_1(FlipPageInfo flipPageInfo_1) {
		this.flipPageInfo_1 = flipPageInfo_1;
	}

	public FlipPageInfo getFlipPageInfo_2() {
		return flipPageInfo_2;
	}

	public void setFlipPageInfo_2(FlipPageInfo flipPageInfo_2) {
		this.flipPageInfo_2 = flipPageInfo_2;
	}

	public FlipPageInfo getFlipPageInfo_3() {
		return flipPageInfo_3;
	}

	public void setFlipPageInfo_3(FlipPageInfo flipPageInfo_3) {
		this.flipPageInfo_3 = flipPageInfo_3;
	}

	public FlipPageInfo getFlipPageInfo_4() {
		return flipPageInfo_4;
	}

	public void setFlipPageInfo_4(FlipPageInfo flipPageInfo_4) {
		this.flipPageInfo_4 = flipPageInfo_4;
	}

	public FlipPageInfo getFlipPageInfo_5() {
		return flipPageInfo_5;
	}

	public void setFlipPageInfo_5(FlipPageInfo flipPageInfo_5) {
		this.flipPageInfo_5 = flipPageInfo_5;
	}
}
